package com.yx.system.controller;

import com.yx.common.annotation.Log;
import com.yx.common.utils.PageUtils;
import com.yx.common.utils.Query;
import com.yx.common.utils.R;
import com.yx.modules.api.annotation.AuthIgnore;
import com.yx.modules.api.annotation.LoginUser;
import com.yx.modules.api.entity.TbUser;
import com.yx.system.entity.TdCollection;
import com.yx.system.service.TdCollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 收藏控制器
 */
@RestController
@RequestMapping("/sys/collection")
public class TdCollectionController2 {
    @Autowired
    private TdCollectionService tdCollectionService;

    /**
     * 按ID查询收藏
     *
     * @return
     */
    @Log("按ID查询收藏")
    @PostMapping("findById")
    public R findById(int id) {
        return R.ok().put("collection", tdCollectionService.selectByPrimaryKey(id));
    }


    /**
     * 查询所有
     *
     * @param map
     * @return
     */
    @AuthIgnore
    @PostMapping("findAllByCondition")
    public R findAllByCondition(@RequestParam Map<String, Object> map) {
        Query query = new Query(map);
        List<TdCollection> tdCollectionList = tdCollectionService.queryList(query);
        int total = tdCollectionService.queryTotal(query);
        PageUtils pageUtil = new PageUtils(tdCollectionList, total, query.getLimit(), query.getPage());
        return R.ok().put("TdCategoryList", pageUtil);
    }

    /**
     * 新增或修改
     *
     * @return
     */
    @Log("新增或修改")
    @PostMapping("saveOrUpdate")
    public R saveOrUpdate(TdCollection tdCollection, @LoginUser TbUser tbuser) {
        tdCollectionService.insert(tdCollection);
        return R.ok();
    }

    /**
     * 删除 (软删除)
     *
     * @return
     */
    @PostMapping("delete")
    public R delete(Integer ids[]) {
        tdCollectionService.deleteByPrimaryKey(ids);
        return R.ok();
    }
}
